import { _decorator, Collider2D, IPhysics2DContact } from "cc";
import { Player } from "../player/Player";
import { BasePowerUp, powerUpConfig } from "./BasePowerUp";
import { PowerUpType } from "../enums/GameEnums";
const { ccclass } = _decorator;

@ccclass("PowerUp")
@powerUpConfig({
  duration: 10, // 道具效果持续10秒
  effectType: PowerUpType.SINGLE_SHOT,
})
export class PowerUp extends BasePowerUp {
  protected applyEffect() {
    const collider = this.node.getComponent(Collider2D);
    if (!collider) return;

    const otherCollider = collider.contacts[0]?.otherCollider;
    if (!otherCollider) return;

    const player = otherCollider.getComponent(Player);
    if (player) {
      player.changeShootMode(this.getEffectType());
    }
  }
}
